<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="context"
            class="input-with-select"
            clearable
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 表格 -->
      <el-table :data="tableData" style="width: 100%" border stripe>
        <el-table-column label="#" width="80" type="index" align="center">
        </el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="200"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="180"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="order_pay" label="是否付款" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_pay !== '0'" type="success"
              >已付款</el-tag
            >
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" align="center">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" align="center">
          <template slot-scope="scope">
            {{
              $dayjs(scope.row.create_time).format('YYYY-MM-DD HH:mm:ss')
            }}=={{ scope.row.create_time }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template>
            <div class="btns">
              <el-button
                icon="el-icon-edit"
                size="mini"
                type="primary"
                @click="openDialog('edit')"
              ></el-button>
              <el-button
                icon="el-icon-location"
                size="mini"
                type="success"
                @click="openDialog('load')"
              ></el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <!--分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="orderList.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
        > >
      </el-pagination>

      <!-- 对话框 -->
      <el-dialog :title="logTitle" :visible.sync="dialogVisible" width="50%">
        <!-- 搜索 -->
        <el-form
          :model="ruleForm"
          status-icon
          ref="formData"
          label-width="90px"
          v-if="logType == 'edit'"
        >
          <el-form-item
            label="省市区/县"
            prop="city"
            :rules="{
              required: true,
              message: '输入不能为空',
              trigger: 'blur',
            }"
          >
            <el-input
              type="text"
              v-model="ruleForm.city"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="详细地址"
            prop="area"
            :rules="{
              required: true,
              message: '输入不能为空',
              trigger: 'blur',
            }"
          >
            <el-input
              type="text"
              v-model="ruleForm.area"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>

        <!-- 进度 -->
        <el-timeline>
          <el-timeline-item
            v-for="item in kdData"
            :key="item.ftime"
            :timestamp="item.time"
          >
            {{ item.context }}
          </el-timeline-item>
        </el-timeline>
        <span slot="footer" class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>
          <el-button type="primary" @click="confirmData">确 定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
import { orderlistAPI, kuaidiAPI } from '@/api/goods.js'
export default {
  name: '',
  data() {
    return {
      ruleForm: {
        city: '',
        area: ''
      },
      tableData: [],
      context: '',
      orderList: {
        canshu: '',
        pagenum: 1,
        pagesize: 5
      },
      // 数据总条数
      total: 0,
      logTitle: '',
      logType: '',
      dialogVisible: false,

      //快递
      kdData: []
    }
  },
  created() {
    this.initData()
  },
  computed: {
  },
  methods: {
    //点击取消
    cancel() {
      this.closeDialog()
    },
    //点击确认
    confirmData() {
      if (this.logType == 'edit') {
        //兜底校验
        this.$refs.formData.validate(val => {
          if (val) {
            this.$message.success('修改成功！')
            this.closeDialog()
          } else {
            this.$message.error('请正确输入！')
          }
        })
      } else {
        this.closeDialog()
      }

    },

    //重置
    reset() {
      this.$refs.formData.resetFields()
    },
    //关闭对话框
    closeDialog() {
      // this.ruleForm = {
      //   city: '',
      //   area: ''
      // },
      if (this.logType == 'edit') {
        this.reset()
      }
      this.dialogVisible = false
    },
    //openDialog()  打开对话框
    async openDialog(type) {
      this.dialogVisible = true
      if (type === 'edit') {
        this.logType = 'edit'
        this.logTitle = '修改地址'
      } else {
        this.logType = 'jindu'
        this.logTitle = '物流进度'
        const oid = 804909574412544580
        const res = await kuaidiAPI(oid)
        this.kdData = res.data

        console.log(this.kdData, 9999);
      }
    },
    //
    handleSizeChange(val) {
      console.log(val, 111);
      this.orderList.pagesize = val
      this.initData()
    },

    //
    handleCurrentChange(val) {
      console.log(val, 222);
      this.orderList.pagenum = val
      this.initData()
    },

    //初始化渲染
    async initData() {
      const res = await orderlistAPI(this.orderList)
      console.log(res, 'orderlist');
      this.total = Number(res.data.total)
      console.log(this.total, 'total');
      this.tableData = res.data.goods

    }
  }
}
</script>
<style lang='less'  scoped>
.el-card {
  margin-top: 20px;

  .el-input {
    margin-bottom: 20px;
  }
}

.jj {
  color: red !important;
  font-size: 14px !important;
}
</style>
